﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Layouts/Form.Master" AutoEventWireup="true" CodeBehind="UserChoice.aspx.cs" Inherits="HHMMS.UI.Modules.Workflow.UserChoice" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="../../Widgets/core/tree/ui.tree.css" type="text/css" rel="stylesheet" />
    <web:Script ID="Script1" src="~/Widgets/core/tree/ui.tree.js" runat="server" />
    <style type="text/css">
        .left{ width:49%; float:left;}
        .right{ width:49%; float:right;}
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Content" runat="server">
    <div class="left"></div>
    <div class="right"></div>
    <script language="javascript" type="text/javascript">
        //获取从父窗口传过来的值
        var api = frameElement.api, W = api.opener;

        $(function () {
            $.dataservice("WFAPI$GetNextAvtivities", api.data || {}, function (result) {
                if (!result) return;
                var ul = $("<ul class='choice'>");
                $.each(result, function (index, item) {
                    $("<li><label for='choice" + item.ActivityId + "'>" + item.ActivityName + "</label><input id='choice" + item.ActivityId + "' value='" + item.ActivityId + "' type='radio' name='choice' isend='" + item.IsEnd + "' /></li>").appendTo(ul);
                });
                ul.find(":radio").click(function () {
                    var activityId = $(this).val();
                    var isEndActi = $(this).attr("isend");
                    $.dataservice("WFAPI$GetParticipantTree", { workflowId: api.data.workflowId, activityId: activityId }, function (nodes) {
                        if (nodes && nodes.length > 0) {
                            $(".right").tree({
                                source: 'array',
                                data: nodes,
                                showCheck: true,
                                cascadeCheck: true
                            });
                        } else if (isEndActi == 'true') {
                            $(".right").html("结束步骤无处理人！");
                        }
                    });
                }).first().click();
                ul.appendTo($(".left"));
            });
        });

        function getData() {
            var partIds = [];

            if ($(":checked").size() <= 0) {
                alert("请选择下一处理环节！");
                return false;
            }

            if ($(":checked").attr("isend") == 'true')
                return partIds;
            
            var choiceNodes = $('.right').tree().getSelectNodes();
            $.each(choiceNodes, function (index, node) {
                if (node.type == 2) {
                    partIds.push(node.id);
                }
            });

            if (partIds.length <= 0) {
                alert("请选择下一环节处理人！");
                return false;
            }

            return partIds;
        }
    </script>
</asp:Content>
